#include <stdlib.h>

#include "CuTest.h"

#include "test_sprout.h"
#include "sprout.h"
#include "sprout_util.h"

void test_c_string_to_json_string_simple(CuTest *tc)
{
    const char *ex = "\"sprout\"";
    const char *str = "sprout";
    char *ac = c_string_to_json_string(str);
    CuAssertStrEquals(tc, ex, ac);
    free_string(ac);
}

void test_json_string_to_c_string_simple(CuTest *tc)
{
    const char *ex = "sprout";
    const char *use = "\"sprout\"";
    char *ac = json_string_to_c_string(&use);
    CuAssertPtrNotNull(tc, ac);
    CuAssertStrEquals(tc, ex, ac);
    free_string(ac);
}

void test_json_string_to_c_string_unicode(CuTest *tc)
{
    const char *ex = "\"_\\_/_\b_\f_\n_\r_\t_一_𐊀";
    char *use = read_file("./tests/data/string.json");
    const char *use_ = use;
    char *ac = json_string_to_c_string(&use_);
    CuAssertPtrNotNull(tc, ac);
    CuAssertStrEquals(tc, ex, ac);
    free_string(ac);
    free_string(use);
}

CuSuite *test_string_suite()
{
    CuSuite *suite = CuSuiteNew();
    SUITE_ADD_TEST(suite, test_c_string_to_json_string_simple);
    SUITE_ADD_TEST(suite, test_json_string_to_c_string_simple);
    SUITE_ADD_TEST(suite, test_json_string_to_c_string_unicode);
    return suite;
}
